package com.zsr.rabbitmq.three;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.zsr.rabbitmq.utils.RabbitMqUtils;

import java.util.Scanner;

/**
 * 实验目的：消息在手动应答时是不丢失的，返回队列中重新消费
 * @author zsr
 * @date 2021/8/1 21:09
 */
public class Task02 {
    //队名
    public static final String TASK_QUEUE_NAME ="ack_queue";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();
        //开启发布确认策略
        channel.confirmSelect();

        boolean durable =true;//队列是否持久化
        //声明队列
        channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false, null);

        //从控制台输入信息
        Scanner scanner=new Scanner(System.in);

        while (scanner.hasNext()){
            String next = scanner.next();
            //第三个参数，消息持久化
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,next.getBytes("utf-8"));
            System.out.println("生产者发出消息");

        }

    }
}
